<html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="cache-control" content="no-cache">
    </head>
	<body>
		<link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/jquery-ui-1.10.4.custom/css/ui-lightness/jquery-ui-1.10.4.custom.min.css" />
        <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/font-awesome/css/font-awesome.min.css" />
        <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/bootstrap/css/bootstrap.min.css" />
        
        <!-- 加载本页需要的三方插件样式 -->
	    <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/DataTables/media/css/jquery.dataTables.css">
	    <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/DataTables/extensions/TableTools/css/dataTables.tableTools.min.css">
	    <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/DataTables/media/css/dataTables.bootstrap.css">
	    <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/jquery-tablesorter/themes/blue/style-custom.css">
	    <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/jquery-bootstrap-wizard/custom.css">
	    <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/jquery-steps/css/jquery.steps.css">
        <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/animate.css/animate.css" />
        <link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/iCheck/skins/all.css" />
    	<link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css">
    	<link type="text/css" rel="stylesheet" href="/Apollo/madmin/vendors/user.css/jquery.ui.all.css">
		<!-- 加载主题风格样式 -->
        <link type="text/css" rel="stylesheet" href="/Apollo/madmin/css/themes/style1/orange-blue.css" class="default-style" />
        <link type="text/css" rel="stylesheet" href="/Apollo/madmin/css/themes/style1/orange-blue.css" id="theme-change" class="style-change color-change" />
        <link type="text/css" rel="stylesheet" href="/Apollo/madmin/css/style-responsive.css" />
						<table width="380px" height="290px">
							<tr>
								<td>
									<div id="menuTree" style="border:0px;padding:0px 0 0px 0;margin:0;width:100%;height:100%;"></div>
								</td>
							</tr>
						</table>
		<script src="/Apollo/madmin/js/jquery-1.10.2.min.js"></script>
		<script src="/Apollo/madmin/js/jquery-migrate-1.2.1.min.js"></script>
	    <script src="/Apollo/madmin/js/jquery-ui.js"></script>
	    
	    <!-- 加载 bootstrap 和三方插件 js -->
	    <script src="/Apollo/madmin/vendors/bootstrap/js/bootstrap.min.js"></script>
	    <script src="/Apollo/madmin/vendors/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js"></script>
	    <script src="/Apollo/madmin/js/html5shiv.js"></script>
	    <script src="/Apollo/madmin/js/respond.min.js"></script>
	    <script src="/Apollo/madmin/vendors/jquery-cookie/jquery.cookie.js"></script>
	    <script src="/Apollo/madmin/vendors/iCheck/icheck.min.js"></script>
	    <script src="/Apollo/madmin/vendors/iCheck/custom.min.js"></script>
	    <script src="/Apollo/madmin/vendors/jquery-notific8/jquery.notific8.min.js"></script>
	    <script src="/Apollo/madmin/vendors/jquery-pace/pace.min.js"></script>
	    <script src="/Apollo/madmin/vendors/holder/holder.js"></script>
	    <script src="/Apollo/madmin/vendors/responsive-tabs/responsive-tabs.js"></script>
	    <script src="/Apollo/madmin/vendors/moment/moment.js"></script>
		<script src="/Apollo/madmin/vendors/bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
	    <script src="/Apollo/madmin/vendors/DataTables/media/js/jquery.dataTables.js"></script>
	    <script src="/Apollo/madmin/vendors/DataTables/media/js/dataTables.bootstrap.js"></script>
	    <script src="/Apollo/madmin/vendors/DataTables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
    	<script src="/Apollo/madmin/vendors/jquery-tablesorter/jquery.tablesorter.js"></script>
    	<script src="/Apollo/madmin/js/table-advanced.js"></script>
	    <script src="/Apollo/madmin/vendors/jquery-validate/jquery.validate.min.js"></script>
	    <script src="/Apollo/madmin/vendors/jquery-validate/message_zh.js"></script>
	    <script src="/Apollo/madmin/vendors/jquery-steps/js/jquery.steps.min.js"></script>
	    <script src="/Apollo/madmin/vendors/jquery-bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>

	    <!-- 加载本页面对应的js -->
		<script src="/Apollo/madmin/vendors/dhtmlxtree/Arraylist.js"></script>
		<script src="/Apollo/madmin/vendors/dhtmlxtree/dhtmlxcommon.js"></script>
		<script src="/Apollo/madmin/vendors/dhtmlxtree/dhtmlxmenu.js"></script>
		<script src="/Apollo/madmin/vendors/dhtmlxtree/dhtmlxtree.js"></script>
		<script src="/Apollo/madmin/vendors/dhtmlxtree/dhtmlXTreeExtend.js"></script>
		<script src="/Apollo/madmin/vendors/dhtmlxtree/DivDialogUtil.js"></script>
	    <script src="/views/static/js/export.js"></script>
	    <script src="/views/static/js/form.js"></script>
	    
	    <script type="text/javascript">
		var url = location.href;
		var privilegeUserId =url.split("userid=")[1];
	    var addList = new ArrayList();
	    var delList = new ArrayList();
		userPrivAdjustInit(privilegeUserId);
	    function userPrivAdjustInit(privilegeUserId){
	    	$("#menuTree").children().remove();
	    	$('body').bind('keydown',shieldCommon);
	    	//处理传入的参数
	    	//obj = window.dialogArguments;// 定义一个对象用于接收对话框参数
	    	//处理树
	    	tree =new dhtmlXTreeObject("menuTree","100%","100%",0);
	    	tree.setImagePath("/Apollo/madmin/vendors/dhtmlxtree/image/DhtxTree/csh_books/");
	        tree.enableCheckBoxes(true);
	    	tree.setOnMouseInHandler(beforeOpenNode);
	    	tree.setOnOpenEndHandler(checkSubNodes);
	    	tree.setOnCheckHandler(nodeCheckHandler);
	    	tree.loadXML("/menu/getMenuTree.action");
	    	tree.setXMLAutoLoading("/menu/getElementsByMenuItemID.action");
	    	//把树全展开
	    	tree.openAllItems(null);
	    	
	    	//根据当前选择的（角色、组织、岗位）来获取它对于资源的访问性
	    	requestPrivilegeAndDrawTree(privilegeUserId, "user");
	    	
	    	//初始化addList和delList里的数据。
	    	addList = new ArrayList();
	    	delList = new ArrayList();
	    }
	    
	    var nodeClickArray = new ArrayList(); //节点点击数组
	    var beforeOpenSubNodes;
	    function checkSubNodes(id,state){
	    	//记录点击过的节点，第一次单击则请求数据，然后记录；当再次点击后则不再请求数据。
	    	if(nodeClickArray.contains(id))
	    		return true;
	    	else{
	    		nodeClickArray.add(id);
	    		//2011年4月12日 wangxy
	    		//如果父结点是灰的，则需要对子结点的使用状态进行判断
	    		//如果父结点不是灰的，则所有子结点是可用状态。
	    		var itemColor = tree.getItemColor(id);
	    		//通过节点颜色判断是否有操作权限
	    		if(itemColor.acolor == "#aaaaaa"){
	    			getSubUnitTreeManageable(id);
	    		}
	    		//over
	    	}
	    	if(beforeOpenSubNodes>0)
	    		return true;
	    	if(beforeOpenSubNodes==0 && state == -1){
	    		tree.openItem(id);
	    	}
	        beforeOpenSubNodes = 1;
	    	return true;
	    }
	    function beforeOpenNode(id){
	    	beforeOpenSubNodes = tree.hasChildren(id);
	    	return true;
	    }
	    
	    /**
	     * 树结点点击事件处理
	     * @return
	     */
	    function nodeCheckHandler(id,state){
	    	//state：1是选中，0是未选中
	    	if (state == "1" || state == 1){
	    		if(delList.contains(id))
	    			delList.remove(id);
	    		else if(!addList.contains(id))
	    			addList.add(id);
	    	} else {
	    		if(addList.contains(id))
	    			addList.remove(id);
	    		else if(!delList.contains(id))
	    			delList.add(id);
	    	}
	    }
	    
	    /**
	     * 根据类型获取权限，并且给权限树打挑
	     * @return
	     */
	    function requestPrivilegeAndDrawTree(id,type){
	    	var sURL1 = "/privilege/getPageElementPrivilege.action";
	    	$.ajax( {
	    		url : sURL1,
	    		type : "post",
	    		dataType : "json",
	    		data : {
	    			type : type,
	    			id : id,
	    			isAdminRole : "false"
	    		},
	    		success : function(data) {
	    			if(data.errorMessage == undefined){
	    				//根据资源授权情况，在树上选中结点
	    				for(var k in data.authMap) {
	    				  tree.setCheck(k,1);
	    				}
	    				//tree.enableThreeStateCheckboxes(true);
	    			} else {
	    				if (data.errorMessage == "session timeout")
	    					window.location.href = "/login.jsp";
	    				else
	    					alert(data.errorMessage);
	    			}
	    		},
	    		error : function(XMLHttpRequest,textStatus,errorThrown){
	    			alert("操作失败，可能是网络原因");
	    			// 通常 textStatus 和 errorThrown 之中 
	    		    // 只有一个会包含信息 
	    		    //this;  调用本次AJAX请求时传递的options参数
	    		}
	    	});
	    }
	    </script>
	    
	</body>
</html>	